<?php
class ASmsKuteNew extends CActiveRecord
{
    public function getApps()
    {
        $sql = "SELECT * FROM c_sms_kute_event ORDER BY title ASC";
        $command = Yii::app()->db->createCommand($sql);
        $rows = $command->queryAll();
        return $rows;
    }   
    
    public function InsertSmsKute($data)
    {
        $sql = "INSERT INTO c_sms_kute SET
            eventId=:eventId
            , userId=:userId
            , username=:username
            , title=:title
            , content=:content
            , download=:download
            , hit=:hit
            , price=:price            
            , status=:status
            , create_date=:create_date
            , update_date=:update_date
        ";

        $command = Yii::app()->db->createCommand($sql);
        $command->bindValues($data);
        $result = $command->execute();
        
        $smsId = Yii::app()->db->getLastInsertID();
        return $smsId;
    }
    
    public function UpdateSms($data)
    {
        $sql = "UPDATE c_sms_kute SET
            eventId=:eventId            
            , title=:title
            , content=:content
            , price=:price                                    
            , update_date=:update_date
            WHERE id=:id
        ";

        $command = Yii::app()->db->createCommand($sql);
        $command->bindValues($data);
        $result = $command->execute();                
        return $result;
    }
    
    public function QuickUpdate($data)
    {
        $sql = "UPDATE c_sms_kute SET status=:status WHERE id=:id";
        $command = Yii::app()->db->createCommand($sql);
        $command->bindValues($data);
        $result = $command->execute();
        return $result;
    }
    
    public function DeleteSms($id)
    {
        $sql = "DELETE FROM c_sms_kute WHERE id=" . $id;
        $command = Yii::app()->db->createCommand($sql);
        $result = $command->execute();
        return $result;
    }
    
    public function GetSmsInfo($id)
    {
        $sql = "SELECT * FROM c_sms_kute WHERE id=" . $id;
        $command = Yii::app()->db->createCommand($sql);
        $rows = $command->queryRow();
        return $rows;   
    }
}  
?>